<?php
ini_set('display_errors', 'On');
error_reporting(1);

  require_once("base.php");


  /* Get input data */
  $lsInput = base64_decode(getGet("input"));
  $lsInput = "<getMessagesRequest><IDClient>10002</IDClient></getMessagesRequest>";
  $lrXMLObject = new SimpleXMLElement($lsInput);
  $lnIDClient = $lrXMLObject->IDClient;

  /* connect to DB */
  $App = new BaseClass();
  $App->DBConnect();
  $lrDBResult = $App->SQL->Query("SELECT * FROM Messages WHERE IDClientTo = ".$lnIDClient);
  
  /* Create response */
  $lrXML = new XML();
  $lrXML->StartTag("getMessagesResponse");

  while ($lrMessage = $lrDBResult->fetch_assoc()) {
    $lrXML->StartTag("Message");
      $lrXML->InsertTag("id",$lrMessage["IDMessage"]);
      $lrXML->InsertTag("text",$lrMessage["Message"]);
      $lrXML->InsertTag("crypted",$lrMessage["Crypted"]);
    $lrXML->EndTag("Message");
  }

  $lrXML->EndTag("getMessagesResponse");

  echo $lrXML->getXML();
?>